<template>
	<view id="TAOpusList">
		<view class="TAOpusList_title">
			<view class="opusTile">所有作品</view>
			<view class="new" v-if="userId == userInfo.id" @click="gotoNewOpusList">+创建</view>
		</view>
		<view class="opustList" v-for="(item,index) in opusList" @click="gotoOpusDirectory(item)" :key="index">
			<view class="bgImage">
				<image :src="item.cover" mode="scaleToFill" />
			</view>
			<view class="opusText">
				<view class="title">{{item.title}}</view>
				<view class="content">{{item.content}}</view>
				<view class="content">{{item.dynamic_num}}</view>
			</view>
		</view>
		<view class="" style="margin-top: 200rpx;">
			<u-empty v-if="opusList.length == 0" mode="data"
				icon="http://cdn.uviewui.com/uview/empty/data.png">
			</u-empty>
		</view>
	
	</view>
</template>

<script>
	import {
		mapState,
		mapActions
	} from "vuex"
	export default {
		data() {
			return {
				userId: '',
				opusList: [],
			}
		},
		onBackPress(event) {
			this.gotoPersonalData();
			return true;
		},
		onLoad(option) {
			this.userId = option.userId
			this.getList(option.userId);
		},
		comments: {
			...mapState('user', ['userInfo']),
		},
		methods: {
			gotoPersonalData() {
				uni.redirectTo({
					url: "/pages/home/PersonalData/PersonalData?id=" + this.userId
				});
			},
			getList(userId) {
				this.$api.getList({
					uuid: userId
				}).then(res => {
					this.opusList = res.data;
					console.log("this.opusList", this.opusList)
				})
			},
			gotoNewOpusList() {
				uni.navigateTo({
					url: "/pages/home/PersonalData/newOpusList"
				})
			},
			gotoOpusDirectory(item) {
				uni.navigateTo({
					url: "/pages/home/opusDirectory/opusDirectory?id=" + item.id
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	#TAOpusList {
		width: 100%;
	}

	.TAOpusList_title {
		width: 90%;
		margin: 20rpx auto;
		display: flex;
		align-items: center;
		justify-content: space-between;

		.opusTile {
			font-size: 40rpx;
		}

		.new {
			color: #ff6600;
			font-size: 35rpx;
		}
	}

	.opustList {
		width: 100%;
		margin: auto;
		padding: 20rpx;
		display: flex;

		.bgImage {
			// width: 200rpx;
			// height: 200rpx;
			// 	margin-right: 20rpx;
			// image {
			// 	width: 100%;
			// 	height: 100%;
			// 	border-radius: 20rpx;
			// }
		width: 200rpx;
		height: 200rpx;
		margin-right: 20rpx !important;
		image {
			width: 100%;
			height: 100%;
			border-radius:20rpx;
		}
		}

		.opusText {
			width: 70%;
			margin-top: 10rpx;
			.title {
				width: 80%;
				font-size: 30rpx;
				word-wrap: break-word;  
				word-break: break-all;
				text-overflow: ellipsis;
				display: -webkit-box;
				-webkit-box-orient: vertical;
				-webkit-line-clamp: 2;
				/* 这里是超出几行省略 */
				overflow: hidden;
			}
			
			.content {
				width: 80%;
				font-size: 28rpx;
				margin: 10rpx 0;
				color: #888;
				word-wrap: break-word;
				word-break: break-all;
				text-overflow: ellipsis;
				display: -webkit-box;
				-webkit-box-orient: vertical;
				-webkit-line-clamp: 1;
				/* 这里是超出几行省略 */
				overflow: hidden;
			}
		}
	}
</style>